'use strict';

const Service = require('egg').Service;

class ProjectService extends Service {
    async findAll() {
        const proList = await this.app.mysql.select('project', {
            orders: [[ 'id', 'desc' ]], // 排序方式
        });
        return proList;
    }

    async findOne(id) {
        const project = await this.app.mysql.get('project', { id });
        return project;
    }

    async insert({ name, score }) {
        const result = await this.app.mysql.insert('project', {
            name,
            score,
        });
        return result.affectedRows === 1;
    }

    async update({ id, name, score }) {
        const result = await this.app.mysql.update('project', {
            id,
            name,
            score,
        });
        return result.affectedRows === 1;
    }

    async delete(id) {
        const result = await this.app.mysql.delete('project', { id });
        return result.affectedRows === 1;
    }
}

module.exports = ProjectService;
